package com.canace.novel.serviece.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.canace.novel.core.common.resp.RestResp;
import com.canace.novel.dto.resp.ImgVerifyCodeRespDto;
import com.canace.novel.manager.redis.VerifyCodeManager;
import com.canace.novel.serviece.ResourceService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author canace
 * @version 1.0
 * @description 资源服务实现类
 * @date 2024/1/20 12:09
 */

@Service
@RequiredArgsConstructor
public class ResourceServiceImpl implements ResourceService {

    private final VerifyCodeManager verifyCodeManager;
    @Override
    public RestResp<ImgVerifyCodeRespDto> getImgVerifyCode() throws IOException {

        // 随机生成个sessionId
        String sessionId = IdWorker.get32UUID();
        ImgVerifyCodeRespDto imgVerifyCodeRespDto = new ImgVerifyCodeRespDto();
        imgVerifyCodeRespDto.setSessionId(sessionId);
        imgVerifyCodeRespDto.setImg(verifyCodeManager.getVerifyCode(sessionId));
        return RestResp.ok(imgVerifyCodeRespDto);
    }
}
